package com.example.bobo.yuejian322.Activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.bobo.yuejian322.Interfa.ClubSeverice;
import com.example.bobo.yuejian322.Interfa.PeixunSeverice;
import com.example.bobo.yuejian322.R;
import com.example.bobo.yuejian322.base.BaseActivity;
import com.example.bobo.yuejian322.bean.DetialClub;
import com.example.bobo.yuejian322.bean.TrainDetial;
import com.squareup.picasso.Picasso;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ClubDetialActivity extends BaseActivity {
    private String id;
    private TextView clubname,intro,place,time,phone;
    private ImageView back,love;
    private ImageView pic;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_club_detial);
        clubname= (TextView) findViewById(R.id.clubdetial_clubname);
        intro= (TextView) findViewById(R.id.clubdetial_jianjie);
        place= (TextView) findViewById(R.id.detial_dizi);
        time= (TextView) findViewById(R.id.detial_shijian);
        phone= (TextView) findViewById(R.id.detial_dianhua);
        back= (ImageView) findViewById(R.id.clubdetial_back);
        love= (ImageView) findViewById(R.id.love);
         pic= (ImageView) findViewById(R.id.image_detialClub);
        id = getIntent().getStringExtra("clubid");


        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://172.24.10.175/workout/api.php/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        ClubSeverice clubSeverice =retrofit.create(ClubSeverice.class);
        Call<DetialClub> listCall = clubSeverice.detialclub(id);

        listCall.enqueue(new Callback<DetialClub>() {
            @Override
            public void onResponse(Call<DetialClub> call, Response<DetialClub> response) {
                DetialClub detialClub =response.body();

                if(response.body()!=null){
                   clubname.setText(detialClub.getClub_name());
                    intro.setText(detialClub.getIntroduction());
                    place.setText(detialClub.getDistrict_name());
                    time.setText(detialClub.getInsert_time());
                    phone.setText(detialClub.getClub_tel());
                   if(detialClub.getThumb()!="")
                    {
                        Picasso.with(ClubDetialActivity.this).load("http://172.24.10.175/workout/Uploads/"+detialClub.getThumb()).error(R.drawable.yundong1).into(pic);

                    }

                }

            }

            @Override
            public void onFailure(Call<DetialClub> call, Throwable t) {

            }
        });

        //返回箭头
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        //关注监听
        love.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                Retrofit retrofit = new Retrofit.Builder()
                        .baseUrl("http://172.24.10.175/workout/api.php/")
                        .addConverterFactory(GsonConverterFactory.create())
                        .build();
                ClubSeverice clubSeverice =retrofit.create(ClubSeverice.class);
                Call<String> listCall = clubSeverice.love(userId,191,id,1);

                listCall.enqueue(new Callback<String>() {
                    @Override
                    public void onResponse(Call<String> call, Response<String> response) {

                        Toast.makeText(ClubDetialActivity.this, "关注成功", Toast.LENGTH_SHORT).show();


                    }

                    @Override
                    public void onFailure(Call<String> call, Throwable t) {

                    }
                });


            }
        });











    }




}
